import { Compiler } from 'webpack'
import fs from 'fs/promises'
const pluginName = 'Plugin1'
class Plugin1 {
    apply(compiler: Compiler) {
        
        compiler.hooks.environment.tap(pluginName, () => {
            console.log('初始化插件之后立即调用')
        })

        compiler.hooks.afterEnvironment.tap(pluginName, () => {
            console.log('初始化插件完成后调用');
        })

        compiler.hooks.entryOption.tap(pluginName, (context, entry) => {
            console.log(context, entry);
            return false;
        })
        compiler.hooks.run.tap(pluginName, (compiler) => {
            console.log('开始打包');
            console.log(compiler.options.context);
        })
        compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
            compilation.hooks.additionalAssets.tapPromise(pluginName, async () => {
                console.log('打包结束向静态页输入一些内容');
            })
        })
    }
}

module.exports = Plugin1